package com.haier.a920changjingyanshidemo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.haier.a920changjingyanshidemo.R;
import com.haier.a920changjingyanshidemo.adapter.HeatViewPapgerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wanghaixin on 17/8/21.
 */
public class EnjoyHeatFragment extends Fragment {

    public static String TAG = EnjoyHeatFragment.class.getSimpleName();
    private ViewPager heatViewpager;
    private TabLayout heatTabLayout;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_enjoyheat, null, false);
        heatViewpager = ((ViewPager) inflate.findViewById(R.id.heat_vp));
        heatTabLayout = ((TabLayout) inflate.findViewById(R.id.heat_tablayout));

        return inflate;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        TabLayout.Tab tab = heatTabLayout.newTab();
        tab.setText("客厅");
        heatTabLayout.addTab(tab);
        TabLayout.Tab tab2 = heatTabLayout.newTab();
        tab2.setText("卧室");
        heatTabLayout.addTab(tab2);
        TabLayout.Tab tab3 = heatTabLayout.newTab();
        tab3.setText("厨房");
        heatTabLayout.addTab(tab3);
        TabLayout.Tab tab4 = heatTabLayout.newTab();
        tab4.setText("卫生间");
        heatTabLayout.addTab(tab4);

        heatTabLayout.setupWithViewPager(heatViewpager);
        heatViewpager.setAdapter(new HeatViewPapgerAdapter(getChildFragmentManager(), getData(),0));


    }

    private List getData() {
        List<Fragment> data = new ArrayList<>();
        EnjoyHeatKeTingFragment enjoyHeatKeTingFragment = new EnjoyHeatKeTingFragment();
        EnjoyHeatWoShiFragment enjoyHeatWoShiFragment = new EnjoyHeatWoShiFragment();
        EnjoyHeatChuFangFragment enjoyHeatChuFangFragment=new EnjoyHeatChuFangFragment();
        EnjoyHeatWeiShengJianFragment enjoyHeatWeiShengJianFragment = new
                EnjoyHeatWeiShengJianFragment();

        data.add(enjoyHeatKeTingFragment);
        data.add(enjoyHeatWoShiFragment);
        data.add(enjoyHeatChuFangFragment);
        data.add(enjoyHeatWeiShengJianFragment);

        return data;
    }
}
